;; Copyright © 2021, 2022 Joshua Branson <jbranso@dismail.de>

(use-modules (gnu))

(use-service-modules networking
                     ssh)

(use-package-modules ssh)

(define (auto-login-to-tty config tty user)
  (if (string=? tty (mingetty-configuration-tty config))
      (mingetty-configuration
       (inherit config)
       (auto-login user))
      config))

;; add an autologin to tty for a tty 2 - 4.
;; When you run this vm, only one will be auto-logged in.
(define %my-base-services
   (modify-services %base-services
    (mingetty-service-type config =>
                           (auto-login-to-tty config "tty1" "joshua"))
    (mingetty-service-type config =>
                           (auto-login-to-tty config "tty2" "joshua"))
    (mingetty-service-type config =>
                           (auto-login-to-tty config "tty3" "joshua"))
    (mingetty-service-type config =>
                           (auto-login-to-tty config "tty4" "joshua"))))

(operating-system
  (host-name "autologin")
  (timezone "America/Indianapolis")
  (locale "en_US.utf8")
  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets (list "/dev/sda"))))
  (file-systems
   (cons*
    (file-system
     (mount-point "/")
     (device "/dev/sda")
     (type "ext4"))
    %base-file-systems))

  (users (cons* (user-account
                 (name "joshua")
                 (comment "Joshua Branson")
                 (group "users")
                 (home-directory "/home/joshua")
                 (supplementary-groups
                  '("kvm" "netdev" "wheel")))
                %base-user-accounts))

  (packages %base-packages)
  ;; Add services to the baseline: a DHCP client and
  ;; an SSH server.
  (services
   (cons*
    (service dhcp-client-service-type)
    (service openssh-service-type
             (openssh-configuration
              (openssh openssh-sans-x)
              (port-number 2222)))
    %my-base-services)))
